package com.ruoyi.consumer;

import com.ruoyi.config.DelayedQueueConfig;
import com.ruoyi.mapper.OrderMapper;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @Author: star
 * @Description:
 * @DateTime: 2023/8/21 9:27
 **/
@Slf4j
@Component
public class DelayQueueConsumer {
    @Autowired
    private OrderMapper orderMapper;
    @RabbitListener(queues = DelayedQueueConfig.DELAYED_QUEUE_NAME)
    public void receive(Message message){
        String msgCode = new String(message.getBody());
        Integer status = orderMapper.getOrderStep(msgCode);
        if (status != null && status == 1){
            boolean result = orderMapper.updateOrderState(msgCode);
            System.out.println("延时队列--当前时间" + new Date() + ",修改订单"+msgCode+"订单状态为超时是否成功："+result );
        }
        //拿到code,查数据库如果没支付，确认一下，30s超时修改成超时
    }
}
